package com.xiaofu.sharding.contoller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaofu.sharding.mapper.DwdSurveySummInfo2015DfRepository;
import com.xiaofu.sharding.mapper.SysUserRepository;
import com.xiaofu.sharding.model.DwdSurveySummInfo2015Df;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: xiaofu
 * @Description:
 */
@Controller
@RequestMapping
public class TestController {

    @Autowired
    private DwdSurveySummInfo2015DfRepository dwdSurveySummInfo2015DfRepository;

    @Autowired
    private SysUserRepository sysUserRepository;

    @GetMapping(value = "/insertDwd")
    @ResponseBody
    public String insertDwd() {

        dwdSurveySummInfo2015DfRepository.delete(new LambdaQueryWrapper<>());

        for (int i = 0; i < 5; i++) {

            DwdSurveySummInfo2015Df dwdSurveySummInfo2015Df = new DwdSurveySummInfo2015Df();
            dwdSurveySummInfo2015Df.setProjectId(Long.parseLong(i + ""));
            dwdSurveySummInfo2015Df.setUserId(i);
            dwdSurveySummInfo2015Df.setSurveyId("s-" + i);
            dwdSurveySummInfo2015Df.setUniqueId(Long.parseLong(i + ""));
            dwdSurveySummInfo2015DfRepository.insert(dwdSurveySummInfo2015Df);
        }
        return "success";
    }

    @GetMapping(value = "/selectDwd")
    @ResponseBody
    public String selectDwd(String uniqueId) {
        DwdSurveySummInfo2015Df dwdSurveySummInfo2015DfQuery = new DwdSurveySummInfo2015Df();
        if (!StringUtils.isEmpty(uniqueId)) {
            dwdSurveySummInfo2015DfQuery.setUniqueId(Long.parseLong(uniqueId));
        }
        return JSON.toJSONString(dwdSurveySummInfo2015DfRepository.selectList(new LambdaQueryWrapper<>()));
    }

    @GetMapping(value = "/selectUser")
    @ResponseBody
    public String selectUser() {

        return JSON.toJSONString(sysUserRepository.selectList(new LambdaQueryWrapper<>()));
    }


    public static void main(String[] args) {

    }
}
